#pragma once
#include <cmath>
#include <string>
#include <boost/lexical_cast.hpp>

template<typename T>
double round(T val, short bits)
{
	try
	{
		double val_ = boost::lexical_cast<double>(val);
		double ret;
		double dMod = 0.0000001;
		if (val_ < 0.0) dMod = -0.0000001;
		ret = val_;
		ret += (5.0 / pow(10.0, bits + 1.0));
		ret *= pow(10.0, bits);
		ret = floor(ret + dMod);
		ret /= pow(10.0, bits);
		return (ret);
	}
	catch (...)
	{
		return 0.0;
	}
}

#define CAST_INT(v) boost::lexical_cast<int>((v))
#define CAST_STR(v) boost::lexical_cast<std::string>((v))
#define CAST_DOUBLE(v) boost::lexical_cast<double>((v))